package com.vf.admin.client.controller.pay.config.controller;

import cn.hutool.core.util.ObjectUtil;
import com.vf.admin.client.common.ClientBaseController;
import com.vf.admin.client.common.ClientConstants;
import com.vf.admin.client.common.RedisKeys;
import com.vf.admin.client.service.*;
import com.vf.admin.common.entity.Result;
import com.vf.admin.miaodong.entity.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

@Controller
@CrossOrigin
@RequestMapping(value = "/api/pay/config")
public class PayConfigController extends ClientBaseController {
    @Resource
    PaySelectService paySelectService;
    @Resource
    AlipayConfigsService alipayConfigsService;

    @Resource
    WechatPayConfigsService wechatPayConfigsService;

    private boolean checkPer() {
        Integer userId = (Integer) redisUtil.get(RedisKeys.userToken + request.getHeader(ClientConstants.client_toke));
        if(ObjectUtil.notEqual(392, userId)){
            return true;
        }
        return false;
    }


    //-------------支付宝配置--------------------
    @RequestMapping(value = "/alipayList")
    @ResponseBody
    public Result alipayList() {
        List<PaySelect> list = paySelectService.list();
        return this.sucessJSON(list);
    }

    @RequestMapping(value = "/openAlipay")
    @ResponseBody
    public Result openAlipay(String id) {
        if (checkPer()) return this.errorJSON("你没有权限");
        paySelectService.openAlipay(id);
        return this.sucessJSON("成功");
    }

    //-------------支付宝h5--------------------
    @RequestMapping(value = "/alipayH5List")
    @ResponseBody
    public Result alipayH5List() {
        List<AlipayConfigs> list = alipayConfigsService.list();
        return this.sucessJSON(list);
    }

    @RequestMapping(value = "/openAlipayH5")
    @ResponseBody
    public Result openAlipayH5(String id) {
        if (checkPer()) return this.errorJSON("你没有权限");
        alipayConfigsService.openAlipayH5(id);
        return this.sucessJSON("成功");
    }

    //-------------微信配置--------------------
    @RequestMapping(value = "/wxList")
    @ResponseBody
    public Result wxList() {
        List<PaySelect> list = paySelectService.wxList();
        return this.sucessJSON(list);
    }

    @RequestMapping(value = "/openWx")
    @ResponseBody
    public Result openWx(String id) {
        if (checkPer()) return this.errorJSON("你没有权限");
        paySelectService.openWx(id);
        return this.sucessJSON("成功");
    }


    //-------------微信h5--------------------
    @RequestMapping(value = "/wxH5List")
    @ResponseBody
    public Result wxH5List() {
        List<WechatPayConfigs> list = wechatPayConfigsService.list();
        return this.sucessJSON(list);
    }

    @RequestMapping(value = "/openWxH5")
    @ResponseBody
    public Result openWxH5(String id) {
        if (checkPer()) return this.errorJSON("你没有权限");
        wechatPayConfigsService.openH5(id);
        return this.sucessJSON("成功");
    }

}
